#!/usr/bin/env python3  /*设定脚本文件直接能执行*/
# -*- coding:utf-8 -*-   /*设置编码*/
"""
@Author: WANDERSON M.PIMENTA
@Software: PyCharm 、Qt Designer and PySide6
@File: tQWindow.py
@Time: 2024/05/11 16:35
@Function：ctQWindow：窗体控件
"""
from tQQtCore import *
from UI.cores.tJsonSettings import Settings
from .tQWindowStyles import Styles


# 窗体控件
class ctQWindow(QFrame):
    # 初始化
    def __init__(self,
                 parent,
                 layout=Qt.Vertical,
                 margin=0,
                 spacing=2,
                 bg_color="#2c313c",
                 text_color="#fff",
                 text_font="9pt 'Segoe UI'",
                 border_radius=10,
                 border_size=2,
                 border_color="#343b48",
                 enable_shadow=True
                 ):
        super().__init__()

        # 加载设置
        settings = Settings()
        self.settings = settings.items

        # <editor-fold desc="属性">
        self.parent = parent
        self.layout = layout
        self.margin = margin
        self.bg_color = bg_color
        self.text_color = text_color
        self.text_font = text_font
        self.border_radius = border_radius
        self.border_size = border_size
        self.border_color = border_color
        self.enable_shadow = enable_shadow
        # </editor-fold>

        # 设置objectName
        self.setObjectName("pod_bg_app")

        # 应用和更新样式表
        self.f_setStylesheet()

        # <editor-fold desc="布局">
        # 添加布局
        if layout == Qt.Vertical:
            # 垂直布局
            self.layout = QHBoxLayout(self)
        else:
            # 水平布局
            self.layout = QHBoxLayout(self)
        self.layout.setContentsMargins(margin, margin, margin, margin)
        self.layout.setSpacing(spacing)

        # 添加阴影
        if self.settings["custom_title_bar"]:
            if enable_shadow:
                self.shadow = QGraphicsDropShadowEffect()
                self.shadow.setBlurRadius(20)
                self.shadow.setXOffset(0)
                self.shadow.setYOffset(0)
                self.shadow.setColor(QColor(0, 0, 0, 160))
                self.setGraphicsEffect(self.shadow)
        # </editor-fold>

    # 应用和更新样式表
    def f_setStylesheet(self,
                        bg_color=None,
                        border_radius=None,
                        border_size=None,
                        border_color=None,
                        text_color=None,
                        text_font=None
                        ):
        # CHECK BG COLOR
        if bg_color is not None:
            internal_bg_color = bg_color
        else:
            internal_bg_color = self.bg_color

        # CHECK BORDER RADIUS
        if border_radius is not None:
            internal_border_radius = border_radius
        else:
            internal_border_radius = self.border_radius

        # CHECK BORDER SIZE
        if border_size is not None:
            internal_border_size = border_size
        else:
            internal_border_size = self.border_size

        # CHECK BORDER COLOR
        if text_color is not None:
            internal_text_color = text_color
        else:
            internal_text_color = self.text_color

        # CHECK TEXT COLOR
        if border_color is not None:
            internal_border_color = border_color
        else:
            internal_border_color = self.border_color

        # CHECK TEXT COLOR
        if text_font is not None:
            internal_text_font = text_font
        else:
            internal_text_font = self.text_font

        self.setStyleSheet(Styles.bg_style.format(
            _bg_color=internal_bg_color,
            _border_radius=internal_border_radius,
            _border_size=internal_border_size,
            _border_color=internal_border_color,
            _text_color=internal_text_color,
            _text_font=internal_text_font
        ))
